package com.exam.api.modules.file.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.exam.api.modules.file.service.TblFileService;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.file.dto.FileBase64DTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author 北橙
 * @Create 2023/5/4
 * @Description 文件相关接口
 * @Version 1.0
 */
@Tag(name = "(客户端) 文件相关接口", description = "(客户端) 文件相关接口")
@RestController
@RequestMapping("/file")
@TinyResponse
@SaCheckLogin
public class FileController {

    @Resource
    private TblFileService tblFileService;


    @Operation(summary = "上传文件", description = "上传文件(注意在文件不需要长时间存储请使用临时上传！！！)")
    @PostMapping("/upload")
    public FileInfo uploadFile(@RequestParam("file") MultipartFile file) {
        return tblFileService.uploadFile(file);
    }


    @Operation(summary = "上传Base64文件", description = "上传文件(注意在文件不需要长时间存储请使用临时上传！！！)")
    @PostMapping("/uploadBase64")
    public FileInfo uploadFileBase64(@RequestBody FileBase64DTO dto) {
        return tblFileService.uploadFileBase64(dto);
    }
}
